package com.example.demo.gateway;

import com.alibaba.nacos.api.exception.NacosException;
import com.example.demo.nacos.NacosNamespaceLoader;
import com.google.common.collect.Lists;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.server.PathContainer;
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.springframework.http.server.PathContainer.parsePath;

@EnableDiscoveryClient
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@RefreshScope
public class GatewayApplication {

    private  static PathPatternParser pathPatternParser = new PathPatternParser();

    public static void main(String[] args) throws IOException, NacosException {
        SpringApplication.run(GatewayApplication.class, args);
        List<PathPattern> pathPatterns = new ArrayList<>();
        PathPattern pathPattern = pathPatternParser.parse("/muser/{a}/*");
        pathPatterns.add(pathPattern);
////        List<String> a = Lists.newArrayList("/muser/**");
        PathContainer path = parsePath("/muser/1/city/wang");
        Optional<PathPattern> optionalPathPattern = pathPatterns.stream()
                .filter(pattern -> pattern.matches(path)).findFirst();
//        System.out.println(optionalPathPattern.isPresent());
    }

}
